package com.ld.control.thread;

import com.ld.control.business.equipment.service.EquipmentService;
import com.ld.control.business.queue.service.PendingNodeQueueService;
import com.ld.control.business.task.service.TaskExampleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class BackgroundThreadTasks {

    @Autowired
    private EquipmentService equipmentService;

    @Autowired
    private PendingNodeQueueService pendingNodeQueueService;

    @Autowired
    private TaskExampleService taskExampleService;


    public void backgroundUpdateEquipmentStatus() {
        while (true) {
            try {
                Thread.sleep(500);
                equipmentService.backgroundUpdateEquipmentStatus();
            } catch (Exception e) {
                log.error("backgroundUpdateEquipmentStatus", e);
            }
        }
    }

    /**
     * 执行
     */
    public void backgroundRunPendingNode() {
        while (true) {
            try {
                Thread.sleep(1000);
                pendingNodeQueueService.backgroundRunPendingNode();
            } catch (Exception e) {
                log.error("backgroundUpdateEquipmentStatus", e);
            }
        }
    }

    public void backgroundCommonTask() {
        while (true) {
            try {
                Thread.sleep(1000);
                taskExampleService.generateEstimatedTime();
            } catch (Exception e) {
                log.error("backgroundCommonTask error", e);
            }
        }
    }
}
